{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "617a981e-a469-492b-87ef-4f527e714e19",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "3d880c58-2e16-4afb-bc5d-a7412eb24a62",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = np.load('通信调制格式识别与分类数据集公开数据/训练集/Y_train.npy')\n",
    "x_train = np.load('通信调制格式识别与分类数据集公开数据/训练集/X_train.npy')\n",
    "\n",
    "x_test = np.load('通信调制格式识别与分类数据集公开数据/测试集/X_test.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "9e3fdb86-5051-49d8-aebc-79e71e2d8e7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(176000, 2, 128)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2393a30d-c902-4507-90e4-e763867e9074",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     16152\n",
       "7     16063\n",
       "2     16047\n",
       "4     16024\n",
       "6     16018\n",
       "8     16010\n",
       "9     15977\n",
       "0     15944\n",
       "5     15942\n",
       "3     15923\n",
       "10    15900\n",
       "dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(y_train.argmax(1)).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "5b7aa1bd-6f1a-4c9f-b53f-f29264bad295",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = x_train.reshape(-1, 256)\n",
    "x_test = x_test.reshape(-1, 256)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "803aea89-1443-44bb-9853-2cecd0990419",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import SGDClassifier\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "\n",
    "from sklearn.model_selection import cross_val_predict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "a835e17e-2659-4b94-81b4-9d3aeb15b647",
   "metadata": {},
   "outputs": [],
   "source": [
    "pred1 = cross_val_predict(GaussianNB(), x_train, y_train.argmax(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "7be151f1-51a5-4eb3-801b-947ad2884719",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20875"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(y_train.argmax(1) == pred1).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "163513e6-3f89-4755-b787-1cd01ea587da",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = GaussianNB().fit(x_train, y_train.argmax(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e9c0d45e-9fb7-4d7c-85a0-93e25258c467",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([8, 7, 3, ..., 6, 2, 7])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "e2e614c7-6bfc-40a5-9f0c-9d3c53f9b90b",
   "metadata": {},
   "outputs": [],
   "source": [
    "submit = np.zeros((len(x_test), 11))\n",
    "submit[np.arange(len(x_test)), model.predict(x_test)] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9df998da-70ad-420c-b3ac-f338c527824a",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save('submit.npy', submit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "835f8204-859d-4dac-ae13-8a88a874b139",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
